<template>
  <div class="box">
      <!--  -->
      <vue-particles
      class="login-bg"
      color="#39AFFD"
      :particleOpacity="0.7"
      :particlesNumber="100"
      shapeType="circle"
      :particleSize="4"
      linesColor="#8DD1FE"
      :linesWidth="1"
      :lineLinked="true"
      :lineOpacity="0.4"
      :linesDistance="150"
      :moveSpeed="3"
      :hoverEffect="true"
      hoverMode="grab"
      :clickEffect="true"
      clickMode="push"
    >
    </vue-particles>
      <!--  -->
    <div class="dl">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item prop="username">
          <el-input
            v-model="ruleForm.username"
            prefix-icon="el-icon-user-solid"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="ruleForm.password"
            prefix-icon="el-icon-unlock"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >立即创建</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        username: "admin",
        password: "123456",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 5, max: 5, message: "长度5个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 6, message: "长度6字符", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert('submit!');
          this.$axios.post("login", this.ruleForm).then((res) => {
            // console.log(res.data.token)
            // console.log(res)
            if (res.meta.status == 200) {
              sessionStorage.setItem("token", res.data.token);
              this.$store.commit("yhm", this.ruleForm.username);
              this.$router.push("/index");
              this.$message({
                message: "ok 你可以进去了",
                type: "success",
              });
            }else{
                this.$message.error('md 不对 gun');
                return false ;
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
<style scoped>
/* .box {
  width: 100%;
  height: 753px;
  background-color: thistle;
} */
.dl {
  width: 400px;
  height: 200px;
  position: absolute;
  top: 40%;
  left: 35%;
  text-align: center;
  background-color: white;
  border-radius: 10px;
}
.login-bg {
 width: 100%;
 height: 100vh;
 background: #3e3e3e;
}
</style>